<template>
  <view class="wrap">
    <view class="header">
      <image
        class="header-bg"
        v-if="type == '9'"
        src="https://ainengli.meilianshuke.com/jkhx/weight/phychology-bg1.png"
        mode="scaleToFill"
      />
      <image
        class="header-bg"
        v-if="type == '8'"
        src="https://ainengli.meilianshuke.com/jkhx/weight/phychology-bg2.png"
        mode="scaleToFill"
      />
    </view>
    <view class="content-box">
      <view class="content-main">
        <text class="questionnaire-name">{{ questionnaireName }}</text>
        <view class="item">
          <text class="item-text">得分：</text>
          <text class="item-value">{{ scoreInfoData.score }}分</text>
        </view>
        <view class="item">
          <text class="item-text">判断：</text>
          <text class="item-value">{{
            type == '9' ? scoreInfoData.symptom : scoreInfoData.conclusion
          }}</text>
        </view>
        <view class="title">
          <view class="title-icon" />
          <text class="title-text">结果说明</text>
        </view>
        <text class="title-content" style="margin-bottom: 48rpx">{{
          type == '9'
            ? scoreInfoData.conclusion
            : '量表得分超过60分，建议立即前往医院获取专业评估。\n注：量表结果仅供测试者参考，具体请以医院专业心理/精神科的评定。'
        }}</text>
      </view>
    </view>
  </view>
</template>
<script setup lang="ts">
import { onLoad, onShow } from '@dcloudio/uni-app'
import { ref } from 'vue'
import { question_score } from '../../api/sleep'

const questionnaireName = ref('抑郁自评量表（SDS）')

const type = ref('')
const userInfo = ref()
const scoreInfoData = ref({
  conclusion: '',
  score: '',
  symptom: ''
})

onShow(() => {
  if (uni.hideHomeButton) {
    uni.hideHomeButton()
  }
})

onLoad((options) => {
  userInfo.value = JSON.parse(uni.getStorageSync('userInfo')).patientInfo

  if (options && options.type) {
    type.value = options.type
    switch (options.type) {
      case '8':
        questionnaireName.value = '焦虑自评量表（SAS）'
        break
      case '9':
        questionnaireName.value = '抑郁自评量表（SDS）'
        break
      default:
        break
    }
    const params = {
      id: options.id,
      empi: userInfo.value.empi
    }
    question_score(params).then((res) => {
      if (res.code == 0) {
        scoreInfoData.value = res.data
      }
    })
  }
})
</script>
<style lang="scss" scoped>
.wrap {
  position: relative;
  min-height: 100vh;
}

.header-bg {
  width: 100%;
  height: 574.84rpx;
}

.questionnaire-name {
  display: inline-block;
  margin-bottom: 32rpx;
  font-size: 44rpx;
  font-weight: 700;
  color: #222;
}

.content-box {
  position: absolute;
  top: 384rpx;
  left: 0;
  z-index: 2;
  width: 100%;
  padding: 32rpx;

  .content-main {
    padding: 32rpx;
    background: #fff;
    border: 1rpx solid #fff;
    border-radius: 16rpx;
  }
}

.title {
  display: flex;
  align-items: center;
  margin-bottom: 16rpx;

  .title-icon {
    width: 8rpx;
    height: 32rpx;
    margin-right: 16rpx;
    background-color: #00d1b6;
    border-radius: 0 8rpx 8rpx 0;
  }

  .title-text {
    font-size: 32rpx;
    font-weight: 700;
    color: #222;
  }
}

.item {
  display: flex;
  align-items: center;
  height: 56rpx;
  margin-bottom: 32rpx;

  .item-text {
    font-size: 32rpx;
    font-weight: 700;
    color: #222;
  }

  .item-value {
    font-size: 40rpx;
    font-weight: 700;
    color: #00d1b6;
  }
}

.title-content {
  display: inline-block;
  font-size: 30rpx;
  font-weight: 500;
  line-height: 44rpx;
  color: #666;
}
</style>
